import Util from '../../libs/util';
import common_app from '@/common/store/app';

const app = {
    state: {
        menuList: [],
        currentPath: [
            {
                title: '首页',
                path: '/home',
                name: 'home_index'
            }
        ], // 面包屑数组
    },
    mutations: {
        updateMenulist (state, permissions) {
            let menuList = [];
            state.routers.forEach((item, index) => {
                var temp = Object.assign({}, item);
                if (item.permission && !Util.showThisRoute(item.permission, permissions)) return;
                if (item.children && item.children.length > 0) {
                    var childrenArr = [];
                    childrenArr = item.children.filter(child => {
                        if (child.permission !== undefined && !Util.showThisRoute(child.permission, permissions)) return;
                        return child;
                    });
                    if(childrenArr.length > 0) {
                        temp.children = childrenArr;
                        menuList.push(temp);
                    }
                }
            });
            state.menuList = menuList;
        },
        setCurrentPath (state, pathArr) {
            state.currentPath = pathArr;
        }
    }
};

export default Util.merge(common_app, app);
